
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <p>4321432</p>
        <p>4321423</p>
        <p>44312</p>
        <p>4321423</p>
        <p>43214231</p>
    </div>
    <button>删除p元素</button>
    <script>
        const btn = document.querySelector('button');
        const div = document.querySelector('div');
        btn.addEventListener('click',()=>{
            const nodes = div.children;
            console.log(nodes);
            if(nodes.length > 0){
                div.removeChild(nodes[0]);
                // 禁用按钮
                if(nodes.length == 0) btn.disabled = true;
            }
            
        });
    </script>
</body>
</html>